# scripts是定义接口测试用列.编测试用列脚本
# 导包
import requests
import unittest
from api.login import LoginAPI

class TestLogin(unittest.TestCase):
    def setUp(self):
        self.login_api = LoginAPI()
        self.session = requests.Session()

    def tearDown(self):
        if self.session:
             self.session.close()

    def test01_login_success(self):

        response = self.login_api.get_verify_code(self.session)
        self.assertEqual(200, response.status_code)
        self.assertIn("image", response.headers.get("Content-Type"))
        response = self.login_api.login(self.session, "18371912089", "123456", "8888")
        print(response.json())
        self.assertEqual(200, response.status_code)
        self.assertEqual(1, response.json().get("status"))
        self.assertIn("登陆成功", response.json().get("msg"))


    def test02_username_is_not_exist(self):
        response = self.login_api.get_verify_code(self.session)
        self.assertEqual(200, response.status_code)
        self.assertIn("image", response.headers.get("Content-Type"))
        response = self.login_api.login(self.session, "1837191208", "123456", "8888")
        print(response.json())
        self.assertEqual(200, response.status_code)
        self.assertEqual(-1, response.json().get("status"))
        self.assertIn("账号不存在!", response.json().get("msg"))

    def test03_password_is_error(self):

        response = self.login_api.get_verify_code(self.session)
        self.assertEqual(200, response.status_code)
        self.assertIn("image", response.headers.get("Content-Type"))
        response = self.login_api.login(self.session, "18371912089", "error", "8888")
        print(response.json())
        self.assertEqual(200, response.status_code)
        self.assertEqual(-2, response.json().get("status"))
        self.assertIn("密码错误!", response.json().get("msg"))

#  设置前置处理
#  设置后置处理
# 创建测试方法
# 导包
# import requests
# import unittest
# from api.login import LoginAPI
#
# class TestLoginAPI(unittest.TestCase):
#     def setUp(self):
#         self.login_api = LoginAPI()
#         self.session = requests.Session()
#
#     def tearDown(self):
#         if self.session:
#             self.session.close()
# # 定义测试方法
# # 登录成功
# # 5 集成测试报告
#     def test01_login_success(self):
#
#         response = self.login_api.get_verify_code(self.session)
#         # 断言
#         self.assertEqual(200, response.status_code)
#         self.assertIn("image", response.headers.get("Content-Type"))
#         # 调用登录接口
#         response = self.login_api.login(self.session, "18371912089", "123456","8888")
#         print(response.json())
#         self.assertEqual(200, response.status_code)
#         self.assertEqual(1, response.json().get("status"))
#         self.assertIn("登陆成功", response.json().get("msg"))
#     # 账号不正确
#     def test02_user_is_not_exist(self):
#
#         response = self.login_api.get_verify_code(self.session)
#         # 断言
#         self.assertEqual(200, response.status_code)
#         self.assertIn("image", response.headers.get("Content-Type"))
#     # 调用登录接口
#         response = self.login_api.login(self.session, "1837191208", "123456","8888")
#         print(response.json())
#         self.assertEqual(200, response.status_code)
#         self.assertEqual(-1, response.json().get("status"))
#         self.assertIn("账号不存在", response.json().get("msg"))
#
#     def test03_password_exist(self):
#
#         response = self.login_api.get_verify_code(self.session)
#         # 断言
#         self.assertEqual(200, response.status_code)
#         self.assertIn("image", response.headers.get("Content-Type"))
#         # 调用登录接口
#         response = self.login_api.login(self.session, "18371912089", "error","8888")
#         print(response.json())
#         self.assertEqual(200, response.status_code)
#         self.assertEqual(-2, response.json().get("status"))
#         self.assertIn("密码错误", response.json().get("msg"))
